﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FrmHotel
{
    public partial class FrmHuiYuanJieZhang : Form
    {
        public FrmHuiYuanJieZhang()
        {
            InitializeComponent();
        }

        private void FrmHuiYuanJieZhang_Load(object sender, EventArgs e)
        {
            SataInfo();
            Class1.zhuangtai = 0;
        }
        public void SataInfo()
        {
            this.dataGridView1.AutoGenerateColumns = false;
            string sql = string.Format("select * from VipInfo v,VipType e where e.VipId=v.VpKaType and 1=1");
                string hao = this.textBox1.Text;
            if (!string.IsNullOrEmpty(hao))
            {
                sql += string.Format(" and VpKaHao like '%{0}%' ", hao);
            }
            this.dataGridView1.DataSource = DBHelper.SelectForTable(sql);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            SataInfo();
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int str = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);
            string sql = string.Format("select VpKaHao,VpMoney from VipInfo where VpId={0}", str);
             SqlDataReader reader =DBHelper.SelectMore(sql);
             string hao = "";
             double money = -1;

             if (reader.Read())
             {
                 hao = reader["VpKaHao"].ToString();
                 money = Convert.ToDouble(reader["VpMoney"]);
             }
             reader.Close();
             if (money==0)
             {
                 MessageBox.Show("此卡余额不足！不能结账！");
                 return;
             }
             double ss = Convert.ToInt32(Class1.xfmoney);
          
             if (ss >money)
             {
                 MessageBox.Show("此卡余额不足！不能结账！");
                 return;
             }
            
             if (Class1.yingfum.Equals("0.0"))
             {
                  MessageBox.Show("应付金额为0！不能使用会员！");
                 return;
             }
            DialogResult dr = MessageBox.Show("确定选择此卡号码: "+hao+" ？", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dr == DialogResult.Yes)
            {
                Class1.bianhao = str;
                Class1.zhuangtai = 1;
                this.Close();
                return;
            }            

            
        }
    }
}
